package com.pcdandan.pcdandan.config.proxy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.youyu.financial.gjj.crawler.principal.Ticket;
import com.youyu.financial.gjj.crawler.visitor.http.Proxy;
import com.youyu.financial.gjj.crawler.visitor.http.ProxyFactory;


/**
 * @author zhouRongKang
 * @date 2017/11/10 13:44
 */
@Component
public class ServerProxyFactory implements ProxyFactory {

    private static Logger logger = LoggerFactory.getLogger(ServerProxyFactory.class);

//    @Autowired
//    private ProxyService proxyService;


    @Override
    public Proxy getProxy(Ticket ticket) {
//        BillTicket billTicket = (BillTicket) ticket;
//        if (StringUtils.isEmpty(billTicket.getBankId())) {
//            return null;
//        }
//        try {
//            Result result = proxyService.proxy(ProxyCode.bank, "00");//get by billTicket.getBankId()
//            logger.info("bankId : {} ,load proxy : {}", billTicket.getBankId(), JSONObject.toJSONString(result));
//            if (result.getCode() == 1) {
//                ProxyObj proxyObj = JSONObject.parseObject(JSONObject.toJSONString(result.getResults()), ProxyObj.class);
//                return new Proxy(proxyObj.getIp(), proxyObj.getPort());
//            }
//        } catch (Exception e) {
//            logger.warn("获取代理ip异常", e);
//        }
        return null;
    }
}

class ProxyObj {

    private String id;
    private String ip;
    private Integer port;
    private Integer status;
    private String cloud;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getCloud() {
        return cloud;
    }

    public void setCloud(String cloud) {
        this.cloud = cloud;
    }

    @Override
    public String toString() {
        return "Obj{" +
                "id=" + id +
                ", ip='" + ip + '\'' +
                ", port=" + port +
                ", status=" + status +
                ", cloud='" + cloud + '\'' +
                '}';
    }
}
